package volkov.ja.model;

import org.apache.commons.lang3.builder.HashCodeBuilder;

public class Movie implements Comparable<Movie> {

	private String id;
	private String imdb;
	private String title;
	private String year;
	private String notes;

	public Movie() {
		id = "";
		imdb = "";
		title = "";
		year = "";
		notes = "";
	}

	public String getId() {
		return id;
	}

	public Movie setId(String id) {
		this.id = id;
		return this;
	}

	public String getImdb() {
		return imdb;
	}

	public Movie setImdb(String imdb) {
		this.imdb = imdb;
		return this;
	}

	public String getTitle() {
		return title;
	}

	public Movie setTitle(String title) {
		this.title = title;
		return this;
	}

	public String getYear() {
		return year;
	}

	public Movie setYear(String year) {
		this.year = year;
		return this;
	}

	public String getNotes() {
		return notes;
	}

	public Movie setNotes(String notes) {
		this.notes = notes;
		return this;
	}

	@Override
	// only compare by title and year
	public int compareTo(Movie movie) {
		if (getTitle().equals(movie.getTitle())) {
			return getYear().compareTo(movie.getYear());
		} else {
			return getTitle().compareTo(movie.getTitle());
		}
	}

	@Override
	// only compare by title and year
	public boolean equals(Object obj) {
		if (obj instanceof Movie) {
			Movie m = (Movie) obj;
			if (getTitle().equals(m.getTitle())
					&& getYear().equals(m.getYear())) {
				return true;
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(getTitle()).append(getYear())
				.toHashCode();
	}

}
